package com.sxd.bill.rela.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtils {
    public static List<String> getGroupNames(String regex) {
        List<String> groupNames = new ArrayList<>();
        Pattern pattern = Pattern.compile("\\(\\?<([a-zA-Z][a-zA-Z0-9]*)>");
        Matcher matcher = pattern.matcher(regex);

        while (matcher.find()) {
            groupNames.add(matcher.group(1));
        }

        return groupNames;
    }

    public static void main(String[] args) {
        String regex = "(?<name>\\w+)\\s+(?<age>\\d+)";
        List<String> groupNames = getGroupNames(regex);
        System.out.println(groupNames);
    }
}
